1 RMarkdown

Is amazing.

1.2 Key Resources

# PDF Knitting Setup: https://yihui.name/tinytex/ 
# install.packages("tintex")
# tinytex::install_tinytex()

2 How Rmarkdown Works

3 Header 1

3.1 Header 2

3.1.1 Header 3

4 Working with Text

Free-form text.

Make text bold.

Make text italics.

Make text bold + italics.

Talk about code - the tidyverse is awesome

Unordered List:

Ordered List:

  1. First point

  2. Second point

  3. More points

5 Tabset

5.1 Tab 1

This is Tab 1

5.2 Tab 2

This is Tab 2

6 Images

NIT Logo
NIT Logo
NIT Logo

NIT Logo

7 Code

Read in data and print to HTML. Notice effect of df_print: paged option for HTML.

# Bike data
bikes_tbl      <- readRDS("C:/Users/Coding/Documents/GitHub/ss23-bbdp-Julian150397/reporting_rmarkdown/bike_data_s14/bikes_tbl.rds")
bikeshops_tbl  <- readRDS("C:/Users/Coding/Documents/GitHub/ss23-bbdp-Julian150397/reporting_rmarkdown/bike_data_s14/bikeshops_tbl.rds")
orderlines_tbl <- readRDS("C:/Users/Coding/Documents/GitHub/ss23-bbdp-Julian150397/reporting_rmarkdown/bike_data_s14/orderlines_tbl.rds")

bike_orderlines_tbl <- orderlines_tbl %>%
    left_join(bikes_tbl,     by = c("product_id" = "bike_id")) %>%
    left_join(bikeshops_tbl, by = c("customer_id" = "bikeshop_id")) %>%
    mutate(total_price = price_euro * quantity)

bike_orderlines_tbl

We can do data manipulations too. Try changing the YAML code_folding option from none to hide to show.

sales_by_category_tbl <- bike_orderlines_tbl %>%
  dplyr::select(category_2, category_1, total_price) %>%
  
  group_by(category_2, category_1) %>%
  summarise(total_revenue = sum(total_price)) %>%
  ungroup() %>%
  
  arrange(desc(total_revenue)) %>%
  mutate(category_2 = as_factor(category_2) %>% fct_rev())

8 Plots

Plotting works as expected. Try changin:

Static Plots:

g <- sales_by_category_tbl %>%
  ggplot(aes(category_2, total_revenue, fill = category_1)) +
  
  # Geoms
  geom_col() +
  coord_flip() +
  
  # Formatting
  labs(
    title = "Total Revenue by Category",
    x = "", y = "", fill = ""
  )

g
Revenue by Category

Revenue by Category

Interactive plots:

# ggplotly(g)

9 Tables

Static Tables:

table_formatted_tbl <- sales_by_category_tbl %>%
  rename_all(.funs = ~ str_replace(., "_", " ") %>%
               str_to_title()) 

table_formatted_tbl %>% knitr::kable()
Category 2 Category 1 Total Revenue
Race Road 11509156
Trail Mountain 8644966
Triathlon Bike Road 5831716
Cross-Country Mountain 5421144
Endurance Road 5013423
E-Mountain E-Bikes 4962946
All-Road Gravel 3697923
Enduro Mountain 3156837
City Hybrid / City 2115482
Cyclocross Road 1940532
E-Gravel E-Bikes 1936489
Downhill Mountain 1803970
E-City E-Bikes 1509096
E-Trekking E-Bikes 1500894
E-Fitness E-Bikes 1039996
Touring Hybrid / City 877736
Adventure Gravel 702007
Fat Bikes Mountain 391654
Dirt Jump Mountain 371922
E-Road E-Bikes 2919

Dynamic Tables:

table_formatted_tbl

10 Footnotes

This is some text with a Footnote1. This is a second Footnote2.


  1. Citation for Footnote 1↩︎

  2. Citatin for Footnote 2↩︎